package com.wl156.adapters;

import org.ksoap2.serialization.SoapObject;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wl156.R;

public class LogisticCompanyAdapter extends CheckableAdapter implements
		OnClickListener {

	public LogisticCompanyAdapter(Context context, SoapObject data) {
		mInflater = LayoutInflater.from(context);
		mData = data;
		mContext = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_logistic_company,
					null);
		}

		TextView place = (TextView) convertView.findViewById(R.id.place);
		TextView contact = (TextView) convertView.findViewById(R.id.contact);
		
		TextView name = (TextView) convertView.findViewById(R.id.name);
		TextView xinyongscore = (TextView) convertView
				.findViewById(R.id.xinyongscore);
		
		TextView phoneDial = (TextView) convertView.findViewById(R.id.dial);
		phoneDial.setOnClickListener(this);
		
		setTextViewStringFromProperty(position, place, 1);
		setTextViewStringFromProperty(position, contact, 3);
		
		setTextViewStringFromProperty(position, name, 2);
		setTextViewStringFromProperty(position, xinyongscore, 7);
		
		int phoneIndex = 5;
		
		setPhoneView(position, phoneDial, phoneIndex);
		
		super.getView(position, convertView, parent);
		
		if (position % 2 != 0) {
			convertView.setBackgroundColor(Color.parseColor("#F0FAFE"));
		} else {
			convertView.setBackgroundColor(Color.parseColor("#FFFFFF"));
		}
		
		return convertView;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dial:
			Intent i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.parse("tel:" + v.getTag().toString()));
			mContext.startActivity(i);
			break;
		}
	}
}
